#@adminLayout() #define main()

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="type-form">
					<div class="select-list">
						<ul>
							<li>
								文件名称：<input type="text" name="cfiletitle"/>
							</li>
							<!-- <li class="select-time">
								<label>上传时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="beginTime"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
							</li> -->
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	       <div class="btn-group-sm" id="toolbar" role="group">
	            <a class="btn btn-success" onclick="addFile()" id="btnUpload">
	                <i class="fa fa-plus"></i> 上传附件
	            </a>
	            <a class="btn btn-success" onclick="downFiles()" >
	                <i class="fa fa-file"></i> 下载附件
	            </a>
				<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" id="btnRemove">
		            <i class="fa fa-remove"></i> 删除
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-bordered">
			    <table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	
	<iframe id="f_down" frameborder="0" src=""
		style="width: 0px; height: 0px;"></iframe>
		
	<script type="text/javascript">
		var m_id="#(m_id)";
		var cdoc_type="#(cdoc_type)";
		var ctype="#(ctype)";
		var dotype="#(dotype)";
		var prefix = "#(ctx)/sysfile";

		$(function() {
			if(dotype=='view')
			{
				$('#btnUpload').hide();
				$('#btnRemove').hide();
			}
		    var options = {
		        url: prefix + "/list?m_id="+m_id+"&cdoc_type="+cdoc_type,
		        removeUrl: prefix + "/remove",
	            uniqueId: "id",
		        sortName: "cfiletitle",
		        sortOrder: "desc",
		        modalName: "附件",
		        columns: [{
		            checkbox: true
		        },{
					title: '序号',//标题  可不加,
                    width:'80px',
					formatter: function (value, row, index) {
						return index+1;
					}
             	},
		        {
		            field: 'cfiletitle',
		            title: '文件名称',
                    width:'360px',
		            sortable: true
		        },
		        {
		            field: 'cext',
		            title: '文件扩展名',
                    width:'80px',
		            sortable: true,
		            formatter: function(value, row, index) {
		                return value;
		            }
		        },
		        {
		            field: 'cfile_size',
		            title: '文件大小',
                    width:'80px',
		            align: 'center'
		        },
		        {
		            field: 'cupload_user',
                    width:'80px',
		            title: '上传人'
		        },
		        {
		            field: 'dupload_date',
                    width:'150px',
		            title: '上传时间',
		            sortable: true
		        },
		        {
		            title: '操作',
		            align: 'center',
                    width:'100px',
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="downFile(\'' + row.id + '\')"><i class="fa fa-file"></i>下载</a> ');

		    			if(dotype!='view')
		    			{
		    				actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
		    			}
		                
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);

		    $("#bootstrap-table").colResizable({
				liveDrag:true, 
				gripInnerHtml:"<div class='grip'></div>", 
				draggingClass:"dragging", 
	            resizeMode:'overflow'
	        });
		});

		function addFile()
		{
			if(ctype=='multi')
			{
				openWin("多文件上传", prefix+"/addMulti?m_id="+m_id+"&cdoc_type="+cdoc_type);
			}
			else
			{
				openWin("单文件上传", prefix+"/addSingle?m_id="+m_id+"&cdoc_type="+cdoc_type);
			}
			
		}
		
		function downFiles()
		{
			var rows = $.table.selectColumns("id");
			console.log(rows);
        	if (rows.length == 0) {
        	    $.modal.alertWarning("请至少选择一条记录");
        	    return;
        	}
        	var url = prefix+"/downfiles";
			$('#f_down').attr("src", url+"?ids="+rows.join());
        	
		}
		
		function downFile(id)
		{
        	var url = prefix+"/downfiles";
        	var data = { "ids": id};
			$('#f_down').attr("src", url+"?ids="+id);
    	   
		}
		
		function refresh()
		{
			$.table.search();
		}
	</script>
</body>
#end